#include <iostream>
#include <vector>
#include <cstring>
#include <set>
using namespace std;
set<int> clt;
int n;
int sum;
int count;
int vis[1000];
vector<int> ret;

void dfs(int pos,int sum,vector<int>& arr,int cnt)
{
	if(cnt==n)
	{
		clt.insert(sum);
		return;
	}
	for(int i=0;i<n;i++)
	{
		if(!vis[i])
		{
			vis[i]=1;
			dfs(i,sum*10+arr[i],arr,cnt+1);
			vis[i]=0;
		}
	}
}
bool dfs_2(int s,vector<int>& cltv,vector<int> path)
{
    cout<<s<<' '<<sum/2<<endl;
    cout<<path.size()<<' '<<count/2<<endl;
    for(auto& k:path)
        cout<<k<<' ';
    cout<<endl;
	if((double)s==(double)sum/2 && path.size()==count/2)
	{
		ret=path;
		return true;
	}
	if(s>sum/2 || path.size()>count/2)
	{
		return false;
	}
	for(int i=0;i<n;i++)
	{
		if(!vis[i])
		{
			vis[i]=1;
			path.push_back(cltv[i]);
			if(dfs_2(s+(cltv[i]*cltv[i]),cltv,path))
				return true;;	
			vis[i]=0;
			path.pop_back();
		}
	}
	return false;
}
int main()
{
	cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;i++)
		cin>>arr[i];
	for(int i=0;i<n;i++)
	{
		memset(vis,0,sizeof(vis));
		vis[i]=1;
		dfs(i,arr[i],arr,1);
	}
	vector<int> cltv;
	for(auto& t:clt)
	{
		cltv.push_back(t);
		sum+=t*t;
	}
	count=cltv.size();
	
	for(int i=0;i<cltv.size();i++)
	{
		memset(vis,0,sizeof(vis));
		vis[i]=1;
		vector<int> path;
		path.push_back(cltv[i]);
		if(dfs_2(cltv[i],cltv,path))
			break;
	}
	

	
	for(int i=0;i<ret.size();i++)
	{
		cout<<ret[i]<<endl;
	}
	
	return 0;
}
